using System;
using System.ServiceModel;
using SmartClientPlatform.RemoteClientBase;
using WcfService1;

namespace SmartClientPlatform.OMS.Test
{
    public class RemotingHelper
    {
        private readonly static ChannelFactory<IService1Channel> channelFactory;
        static RemotingHelper()
        {
            channelFactory = new ChannelFactory<IService1Channel>("MyEndpoint");
        }

        public static T Execute<T>(Func<IService1, T> func)
        {
            using (var personService = channelFactory.CreateChannel())
            {
                return func(personService);
            }            
        }

        public static void Execute(Action<IService1> action)
        {
            Execute(action.ToFunc());
        }

        private interface IService1Channel : IService1, IClientChannel
        {
        }
    }
}